package com.no1.zy.controller;

import com.no1.zy.pojo.Student;
import com.no1.zy.pojo.User;
import com.no1.zy.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.sql.DataSource;

@Controller
public class HelloController {
    @Autowired
    private DataSource dataSource;

    @GetMapping("hello")
    @ResponseBody
    public String Hello(){
        System.out.println("dataSource ->"+dataSource);
        return "Hello,Spring Boot!";
    }

    @Autowired
    private UserServiceImpl userService;

    @GetMapping("/user/{age}")
    @ResponseBody
    public User querById(@PathVariable Long id){

        return userService.queryById(id);
    }
@GetMapping("index")
    public  String index(Model model){
        model.addAttribute("user",userService.queryById(1L));
   //封装一个学生对象，赋予性别，疯涨到model，传递给index
    Student stu=new Student();
    stu.setStuId(1001).setStuName("张娅").setStuSex("女").setStuAge(18);
    model.addAttribute("stu",stu);
        return "index";
}
}
